package com.project_doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project_doctor.pojo.Institution;
import com.project_doctor.pojo.dto.InstitutionSearchDTO;
import com.project_doctor.service.InstitutionService;
import com.project_doctor.mapper.InstitutionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author xixif
* @description 针对表【t_institution(医疗机构信息表)】的数据库操作Service实现
* @createDate 2025-06-11 11:29:35
*/
@Service
public class InstitutionServiceImpl extends ServiceImpl<InstitutionMapper, Institution>
    implements InstitutionService{
    @Autowired
    private InstitutionMapper institutionMapper;

            @Override
    public Page<Institution> getInstitutionInfo(Integer pageNum, Integer pageSize, InstitutionSearchDTO searchDTO) {
        Page<Institution> page = new Page<>(pageNum, pageSize);
        List<Institution> institutionList = institutionMapper.selectInstitution(page, searchDTO);
        page.setRecords(institutionList);

        // 暂时设置总数为记录数（实际应该通过count查询获取）
        // TODO: 添加专门的count查询方法
        page.setTotal(institutionList.size());

        return page;
    }

    @Override
    public void updateInstitution(Institution institution) {
                Institution oldInstitution = new Institution();
        oldInstitution.setId(institution.getId());
        oldInstitution.setImage(institution.getImage());
        oldInstitution.setName(institution.getName());
        oldInstitution.setPrincipal(institution.getPrincipal());
        oldInstitution.setPhone(institution.getPhone());
        oldInstitution.setAddress(institution.getAddress());
        institutionMapper.updateById(oldInstitution);
    }

    @Override
    public List<Institution> getInstitution() {
        LambdaQueryWrapper<Institution> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Institution::getId, Institution::getName);
        return institutionMapper.selectList(wrapper);
    }
}




